import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;

@WebServlet(name = "LoginServlet",urlPatterns = "/login.do",
initParams ={@WebInitParam(name ="encoding",value="UFT-8"),})
public class LoginServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
      System.out.println("..........初始化..........");
    }
@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String pwd=request.getParameter("password");

        if ("admin".equals(username)&& "123".equals(pwd)){
            HttpSession session=request.getSession();
            session.setAttribute("username",username);
              response.sendRedirect("helloServlet");
        }
    //ServletConfig config=this.getServletConfig("encoding");
//System.gc();
//        String username= request.getParameter("username");
//        String password= request.getParameter("password");
//
//        response.setContentType("text/html;charset=utf-8");
//        PrintWriter out=response.getWriter();
//        out.println("用户名："+username+"<br>");
//        out.println("密码："+password+"<br>");
//    //out.println("编码："+param+"<br>");
//    response.setContentType("text/html;charset=utf-8");
//    ServletContext context=this.getServletContext();
//    System.out.println(context.getServerInfo().toString());
//    PrintWriter out= response.getWriter();
//    InputStream in=context.getResourceAsStream("/WEB-INF/it.properties");
//    Properties prop=new Properties();
//    prop.load(in);
//    out.println("url:"+prop.getProperty("url"));
//    out.println("username:"+prop.getProperty("username"));
//    out.println("password:"+prop.getProperty("password"));
   // out.println("<a href='downfile'>下载查看</a>");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
